package com.mxw.mytools.web;

import com.mxw.mytools.dto.ExcelReadAndProcessAndWriteRequest;
import com.mxw.mytools.dto.ExcelReadAndProcessAndWriteResponse;
import com.mxw.mytools.dto.ExcelReadResponse;
import com.mxw.mytools.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/main")
@Slf4j
public class MainController {

    @Autowired
    private ExcelService excelService;

    @PostMapping("/excel/readAndProcessAndWrite")
    public ExcelReadAndProcessAndWriteResponse test(@RequestBody ExcelReadAndProcessAndWriteRequest request) {
        try {
            ExcelReadAndProcessAndWriteResponse excelReadAndProcessAndWriteResponse = excelService.readAndProcessAndWrite(request);
            return excelReadAndProcessAndWriteResponse;
        } catch (Exception e) {
            log.error("readAndProcessAndWrite执行异常", e);
            ExcelReadAndProcessAndWriteResponse excelReadAndProcessAndWriteResponse
                    = new ExcelReadAndProcessAndWriteResponse();
            excelReadAndProcessAndWriteResponse.setErrorMessage(e.getMessage());
            return excelReadAndProcessAndWriteResponse;
        }


    }

    @GetMapping("/test")
    public ExcelReadResponse test() {
        ExcelReadResponse excelReadResponse = excelService.readExcel("C:\\Users\\m6553\\Desktop\\mytools\\工作簿1.xlsx");

        return excelReadResponse;
    }
}
